package com.dang.test;

import java.util.Random;

public class test2 {
    public static void main(String[] args) {
        //需求：
        //把一维数组中0-15打乱顺序
        //然后按照4个一组的方式添加到二维数组当中

        int[] tempArr = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
        Random random = new Random();

        for (int i = 0; i < tempArr.length; i++) {
            int index = random.nextInt(tempArr.length);
            int temp = tempArr[i];
            tempArr[i] = tempArr[index];
            tempArr[index] = temp;
        }
        //遍历
//        for (int i = 0; i < tempArr.length; i++) {
//            System.out.print(tempArr[i]+"  ");
//        }
        //按照4个一组的方式添加到二维数组当中
        int[][] data = new int[4][4];
        for (int i = 0; i < tempArr.length; i++) {
            data[i/4][i%4] = tempArr[i];

        }
        for (int i = 0; i < data.length; i++) {
            for (int i1 = 0; i1 < data[i].length; i1++) {
                System.out.println(data[i][i1]);
            }
            System.out.println();
        }

        //
        for (int i = 0; i < data.length; i++) {
            for (int i1 = 0; i1 < data[i].length; i1++) {
                System.out.println(data[i][i1]);
            }
            System.out.println();
        }
    }
}
